package com.example.controller;

import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

@RestController
public class HelloWorld {

    @GetMapping("/hello")
    public String hello(String name,int age){
        System.out.println(name + "===" + age);
        return "OK";
    }

    @PostMapping("/addTest")
    public String addTest(@RequestParam(name = "taskName",required = false) String name, String image){
        System.out.println(name + "===" + image);
        return "Ok";
    }

    //字符串集合参数
    @GetMapping("/strList")
    public String strList(String[] list){
        System.out.println(Arrays.toString(list));
        return "OK";
    }

    //集合参数 使用 List<String> 声明参数类型
    //需要添加 @RequestParam 注解

    @GetMapping("/arrList")
    public String arrList(@RequestParam List<String> list){
        System.out.println(list);
        return "OK";
    }

    //日期参数 接口
    @GetMapping("/dateParam")
    public String dateParam(@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime dateTime){

        System.out.println(dateTime);

        return "OK";
    }



}
